home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Average_Module1 / modinit.c < prev    next >
C/C++ Source or Header  |  1998-09-16  |  6KB  |  215 lines

  1.  
  2. /********************************************************************
  3.  
  4.  modinit.c - standard initialisation for Opus 5 modules
  5.              ( ... slightly changed by me ... :-) )
  6.  
  7.  ********************************************************************/
  8.  
  9. #ifndef _DOPUS_MODULE_DEF
  10. #define _DOPUS_MODULE_DEF
  11. #include <dopus/modules.h>
  12. #endif
  13.  
  14. #ifndef CLIB_EXEC_PROTOS_H
  15. #include <clib/exec_protos.h>
  16. #include <pragmas/exec_pragmas.h>
  17. #endif
  18.  
  19. #ifndef EXEC_MEMORY_H
  20. #include <exec/memory.h>
  21. #endif
  22.  
  23. #ifndef CLIB_LOCALE_PROTOS_H
  24. #include <clib/locale_protos.h>
  25. #include <pragmas/locale_pragmas.h>
  26. #endif
  27.  
  28. /********************************************************************/
  29.  
  30. // some prototypes for the functions here
  31. // needed by SAS to create the library header
  32. int  __saveds __UserLibInit( void );
  33. void __saveds __UserLibCleanup( void );
  34.  
  35. struct Library *DOSBase;
  36. struct Library *AslBase;
  37. struct Library *GfxBase;
  38. struct Library *DOpusBase;
  39. struct Library *LayersBase;
  40. struct Library *LocaleBase;
  41. struct Library *UtilityBase;
  42. struct Library *DiskfontBase;
  43. struct Library *GadToolsBase;
  44. struct Library *IntuitionBase;
  45. struct Library *CxBase;
  46.  
  47. #ifdef DATATYPES
  48. struct Library *DataTypesBase;
  49. #endif
  50. #ifdef AREXX
  51. struct Library *RexxSysBase; 
  52. #endif
  53.  
  54. // our module memorypool
  55. APTR mempool;
  56.  
  57. // NEW !! our globally IPC pointer
  58. IPCData *exchange;
  59.  
  60. // Locale pointer
  61. struct DOpusLocale *locale;
  62.  
  63. // a prototype from buildinstrings.c
  64. extern void init_locale_data(struct DOpusLocale *locale);
  65.  
  66. /********************************************************************/
  67.  
  68. // Library initialisation code
  69. int __saveds __UserLibInit()
  70. {
  71.         // Initialise pointers
  72.         AslBase = 0;
  73.         GfxBase = 0;
  74.         DOpusBase = 0;
  75.         LayersBase = 0;
  76.         LocaleBase = 0;
  77.         UtilityBase = 0;
  78.         DiskfontBase = 0;
  79.         GadToolsBase = 0;
  80.         IntuitionBase = 0;
  81.         CxBase = 0;
  82.         locale = 0;
  83.         mempool = NULL;
  84.         exchange = NULL;
  85.                   
  86. #ifdef DATATYPES                  
  87.         DataTypesBase = 0;
  88. #endif            
  89. #ifdef AREXX
  90.         RexxSysBase = 0;
  91. #endif
  92.                                  
  93.         // Get DOS library (can't really fail)
  94.         DOSBase = OpenLibrary( "dos.library", 0 );
  95.  
  96.         // Open other libraries we need
  97.         if( !(AslBase = OpenLibrary("asl.library", 37))              ||
  98.             !(CxBase  = OpenLibrary("commodities.library", 37))      ||
  99.             !(GfxBase = OpenLibrary("graphics.library", 37))         ||          
  100.             !(DOpusBase = OpenLibrary("dopus5.library", 55))         ||
  101.             !(LayersBase = OpenLibrary("layers.library", 37))        ||
  102.             !(UtilityBase = OpenLibrary("utility.library", 37))      ||            
  103.             !(GadToolsBase = OpenLibrary( "gadtools.library", 37))   ||
  104.             !(IntuitionBase = OpenLibrary( "intuition.library", 37)) ||
  105.                                 
  106. #ifdef DATATYPES                                
  107.             !(DataTypesBase = OpenLibrary( "datatypes.library", 39)) ||
  108. #endif                          
  109. #ifdef AREXX
  110.             !(RexxSysBase = OpenLibrary("rexxsyslib.library", 0))    ||
  111. #endif      
  112.             !(DiskfontBase = OpenLibrary("diskfont.library", 37)) )
  113.              return 1;
  114.         
  115.         // Creating our memorypool and use it immediate for the locale
  116.         if( !(mempool = NewMemHandle(4096, 3072, MEMF_CLEAR|MEMF_PUBLIC)) ||
  117.             !(locale = AllocMemH(mempool, sizeof(struct DOpusLocale))) )
  118.              return 1;
  119.  
  120.         init_locale_data(locale);
  121.  
  122.         // Open locale library
  123.         if( LocaleBase = OpenLibrary("locale.library", 38) )
  124.           {
  125.              // Store library pointer
  126.              locale->li_LocaleBase = LocaleBase;
  127.  
  128.              // Open catalog if name supplied
  129.              if( module_info.locale_name )
  130.                {
  131.                   struct TagItem tags[2];
  132.  
  133.                   // If MODULEF_CATALOG_VERSION is set, we do version checking
  134.                   tags[0].ti_Tag = (module_info.flags & MODULEF_CATALOG_VERSION) ? OC_Version : TAG_IGNORE;
  135.                   tags[0].ti_Data = module_info.ver;
  136.                   tags[1].ti_Tag = TAG_DONE;
  137.  
  138.                   // Open catalog
  139.                   locale->li_Catalog = OpenCatalogA( NULL, module_info.locale_name, tags );
  140.                }
  141.  
  142.              // Get default lolale
  143.              locale->li_Locale = OpenLocale( 0 );
  144.           }
  145.         
  146.         return NULL; // Succeeded
  147. }
  148.  
  149.  
  150. // Clean up
  151. void __saveds __UserLibCleanup()
  152. {
  153.      if( mempool )
  154.        {
  155.           if( locale )
  156.             {
  157.                if( LocaleBase )
  158.                  {
  159.                     CloseLocale( locale->li_Locale );
  160.                     CloseCatalog( locale->li_Catalog );
  161.                     CloseLibrary( LocaleBase );
  162.                  }
  163.  
  164.                FreeMemH(locale);
  165.             }
  166.  
  167.           FreeMemHandle( mempool );
  168.        }
  169.                   
  170.      // Close libraries
  171.      CloseLibrary( AslBase );
  172.      CloseLibrary( CxBase );
  173.      CloseLibrary( GfxBase );
  174.      CloseLibrary( DOpusBase );
  175.      CloseLibrary( LayersBase );
  176.      CloseLibrary( DiskfontBase );
  177.      CloseLibrary( UtilityBase );
  178.                   
  179. #ifdef DATATYPES
  180.      CloseLibrary( DataTypesBase );
  181. #endif            
  182. #ifdef AREXX              
  183.      CloseLibrary( RexxSysBase );
  184. #endif        
  185.  
  186.      CloseLibrary( GadToolsBase );
  187.      CloseLibrary( IntuitionBase );
  188.      CloseLibrary( DOSBase );
  189. }
  190.  
  191. /********************************************************************/
  192.  
  193. // This routine is called by DOpus to find out what the module does
  194. // Do not modify it or move it to an other place !!
  195.  
  196. ModuleInfo *__asm __saveds L_Module_Identify( register __d0 int num )
  197. {
  198.      // Return module information
  199.      if( num == -1 )
  200.           return &module_info;
  201.  
  202.      // Valid function number?
  203.      if( num > module_info.function_count ||
  204.          !(module_info.function[num].desc) )
  205.           return 0;
  206.  
  207.      // Return function description
  208.      return (ModuleInfo *) DOpusGetString( locale, module_info.function[num].desc );
  209. }
  210.  
  211. /********************************************************************/
  212.  
  213.  
  214.  
  215.